package cn.edu.tju.core.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration//Tell the Spring container that this is a configuration class
public class SwaggerConfig {
    //Visit the website:http://127.0.0.1:8080/swagger-ui/index.html
    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("TJU SE Project")
                        .description("Tianjin University Software Engineering Project")
                        .version("v1"));

    }

    @Bean
    public OpenAPI openAPI() {
        final String schemeName = "bearerAuth";
        return new OpenAPI()
                .components(new Components().addSecuritySchemes(
                        schemeName,
                        new SecurityScheme()
                                .type(SecurityScheme.Type.HTTP)   // 关键：HTTP + bearer
                                .scheme("bearer")
                                .bearerFormat("JWT")
                ))
                // 全局要求带鉴权（也可只在某些接口上加）
                .addSecurityItem(new SecurityRequirement().addList(schemeName));
    }

}